package problems.contest;

import java.util.HashSet;
import java.util.Set;

/**
 * @author dubulingbo, 2023/8/27 10:28.
 */
public class WCT360 {
    /**
     * T1|
     */
    public int furthestDistanceFromOrigin(String moves) {
        int n = moves.length();
        int left = 0;
        int right = 0;
        int x = 0;
        for (int i = 0; i < n; ++i) {
            if (moves.charAt(i) == 'L') ++left;
            else if (moves.charAt(i) == 'R') ++right;
            else ++x;
        }

        return Math.abs(left - right) + x;
    }


    public long minimumPossibleSum(int n, int target) {
        int cur = 1;
        long ans = 0;
        Set<Integer> set = new HashSet<>();

        for (int i = 0; i < n; ++i) {
            while (set.contains(target - cur)) {
                ++cur;
            }
            set.add(cur);
            ans += cur;
            ++cur;
        }

        return ans;
    }
}
